package com.szpx.service.impl;

import com.szpx.entity.BEQ.kaiban;
import com.szpx.mapper.kaibanMapper;
import com.szpx.service.kaibanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class kaibanServiceImpl implements kaibanService {

    @Autowired
    private kaibanMapper kaibanMapper;

    @Override
    public List<kaiban> getAllCourses() {
        return kaibanMapper.selectAllCourses();
    }

    @Override
    public com.szpx.utils.PageResult<kaiban> getAllCourses(Integer page, Integer size) {
        // 使用PageHelper分页插件
        com.github.pagehelper.PageHelper.startPage(page, size);
        List<kaiban> list = kaibanMapper.selectAllCourses();
        com.github.pagehelper.PageInfo<kaiban> pageInfo = new com.github.pagehelper.PageInfo<>(list);
        
        return new com.szpx.utils.PageResult<>(
            pageInfo.getList(),
            pageInfo.getTotal(),
            pageInfo.getPageNum(),
            pageInfo.getPages()
        );
    }

    @Override
    public List<kaiban> searchCourses(kaiban course) {
        return kaibanMapper.searchCourses(course);
    }

    @Override
    public com.szpx.utils.PageResult<kaiban> searchCourses(kaiban course, Integer page, Integer size) {
        // 使用PageHelper分页插件
        com.github.pagehelper.PageHelper.startPage(page, size);
        List<kaiban> list = kaibanMapper.searchCourses(course);
        com.github.pagehelper.PageInfo<kaiban> pageInfo = new com.github.pagehelper.PageInfo<>(list);
        
        return new com.szpx.utils.PageResult<>(
            pageInfo.getList(),
            pageInfo.getTotal(),
            pageInfo.getPageNum(),
            pageInfo.getPages()
        );
    }

    @Override
    public kaiban getCourseById(Integer id) {
        return kaibanMapper.selectCourseById(id);
    }

    @Override
    public boolean addCourse(kaiban course) {
        return kaibanMapper.insertCourse(course) > 0;
    }

    @Override
    public boolean updateCourse(kaiban course) {
        return kaibanMapper.updateCourse(course) > 0;
    }

    @Override
    public boolean deleteCourse(Integer id) {
        return kaibanMapper.deleteCourse(id) > 0;
    }
}